package com.qcby.types.pojo.page;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SortModel implements Comparable<SortModel>, Serializable {

    /**
     * 排序字段名称
     */
    private String property;

    /**
     * 排序类型升序或降序 asc|desc
     */
    private String direction;

    /**
     * 排序字段顺序 0...n
     */
    private Integer index;

    @Override
    public int compareTo(SortModel o) {
        if (this.index == null || o.index == null) {
            return 0;
        }
        if (this.index > o.index) {
            return 1;
        }
        if (this.index < o.index) {
            return -1;
        }
        return 0;
    }
}
